import { rawRequestClient } from '#/api/request';

// Agent接口类型定义
export interface Agent {
  id?: number;
  name: string;
  description?: string;
  custom_id: string;
  agent_provider_id: number;
  type: 'agent' | 'agent_flow';
  access_type: 'public' | 'private';
  icon_url?: string;
  documentation_url?: string;
  url?: string;
  is_published?: boolean;
  is_last?: boolean;
  version?: number;
  published_version?: string;
  publish_at?: string;
  current_health_status?: string;
  last_health_status_changed_at?: string;
  last_health_status_changed_reason?: string;
  node_config?: any;
  node_coordinate?: any;
  owner_id?: string;
  owner_type?: string;
  created_at?: string;
  created_by?: string;
}

// Agent发布信息类型定义
export interface AgentPublishInfo {
  access_type: 'public' | 'private';
  version: string;
}

// 获取Agent列表
export function getAgentList(params: {
  page?: number;
  size?: number;
  agent_provider_id?: number;
  type?: 'agent' | 'agent_flow';
  is_published?: boolean;
  keyword?: string;
  order_by?: string;
}) {
  return rawRequestClient.get('/agent', { params });
}

// 创建Agent
export function createAgent(data: Partial<Agent>) {
  return rawRequestClient.post('/agent', data);
}

// 根据ID获取Agent详情
export function getAgentDetail(id: number) {
  return rawRequestClient.get(`/agent/${id}`);
}

// 根据自定义ID获取Agent详情
export function getAgentDetailByCustomId(customId: string) {
  return rawRequestClient.get(`/agent/custom-id/${customId}`);
}

// 更新Agent
export function updateAgent(id: number, data: Partial<Agent>) {
  return rawRequestClient.put(`/agent/${id}`, data);
}

// 删除Agent
export function deleteAgent(id: number) {
  return rawRequestClient.delete(`/agent/${id}`);
}

// 发布Agent
export function publishAgent(id: number, data: AgentPublishInfo) {
  return rawRequestClient.post(`/agent/${id}/publish`, data);
}
